<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>mobile 点击小图查看大图</title>
</head>
<body>
	<div class="my-simple-gallery">
		<figure itemprop="associatedMedia" itemscope=""><a href="http://pic1.win4000.com/wallpaper/9/5406ab591a754.jpg" data-size="图片尺寸（格式300X300）"><img src="./img/suoluetu1.jpg"></a></figure>
		<figure itemprop="associatedMedia" itemscope=""><a href="http://tupian.enterdesk.com/2015/lcx/1/26/9/9.jpg" data-size="图片尺寸（格式300X300）"><img src="./img/suoluetu2.jpg"></a></figure>
	</div>

<!-- 给列表使用函数 -->
<!-- initPhotoSwipeFromDOM('.my-simple-gallery'); -->


<!-- 大图展示的容器,看不明白可以直接拿去使用的 -->

<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true" style="">
        <div class="pswp__bg"></div>
        <div class="pswp__scroll-wrap">
            <div class="pswp__container" style="transform: translate3d(0px, 0px, 0px);">
                <div class="pswp__item" style="display: block; transform: translate3d(-1792px, 0px, 0px);">
                    <div class="pswp__zoom-wrap" style="transform: translate3d(288px, 56px, 0px) scale(1);"></div>
                </div>
                <div class="pswp__item" style="transform: translate3d(0px, 0px, 0px);">
                    <div class="pswp__zoom-wrap" style="transform: translate3d(473px, 66.8125px, 0px) scale(0.146484375);"></div>
                </div>
                <div class="pswp__item" style="display: block; transform: translate3d(1792px, 0px, 0px);">
                    <div class="pswp__zoom-wrap" style="transform: translate3d(447px, 44px, 0px) scale(0.6904296875);"></div>
                </div>
            </div>
                <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
            <div class="pswp__ui pswp__ui--fit pswp__ui--hidden">
                <div class="pswp__top-bar">
                    <div class="pswp__counter">
                            4 / 4
                    </div>
                    <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                    <div class="pswp__preloader">
                        <div class="pswp__preloader__icn">
                            <div class="pswp__preloader__cut">
                                <div class="pswp__preloader__donut"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="pswp__caption">
                    <div class="pswp__caption__center"></div>
                </div>
            </div>
        </div>
</div>


<!-- 加载所需JS文件，别看JS文件有点多，但是处理起来效果还是非常棒的，后面会有文件打包下载 -->
<script src="./script/stopExecutionOnTimeout.js"></script>
<script src="./script/photoswipe.min.js"></script>
<script src="./script/photoswipe-ui-default.min.js"></script>

<script>
var initPhotoSwipeFromDOM = function(gallerySelector) {
var parseThumbnailElements = function(el) {
        var thumbElements = el.childNodes, numNodes = thumbElements.length, items = [], figureEl, childElements, linkEl, size, item;
        for (var i = 0; i < numNodes; i++) {
                if (window.CP.shouldStopExecution(1)) {
                        break;
                }
                figureEl = thumbElements;
                if (figureEl.nodeType !== 1) {
                        continue;
                }
                linkEl = figureEl.children[0];
                size = linkEl.getAttribute('data-size').split('x');
                item = {
                        src : linkEl.getAttribute('href'),
                        w : parseInt(size[0], 10),
                        h : parseInt(size[1], 10)
                };
                if (figureEl.children.length > 1) {
                        item.title = figureEl.children[1].innerHTML;
                }
                if (linkEl.children.length > 0) {
                        item.msrc = linkEl.children[0].getAttribute('src');
                }
                item.el = figureEl;
                items.push(item);
        }
        window.CP.exitedLoop(1);
        return items;
};
var closest = function closest(el, fn) {
        return el && (fn(el) ? el : closest(el.parentNode, fn));
};
var onThumbnailsClick = function(e) {
        e = e || window.event;
        e.preventDefault ? e.preventDefault() : e.returnValue = false;
        var eTarget = e.target || e.srcElement;
        var clickedListItem = closest(eTarget, function(el) {
                return el.tagName && el.tagName.toUpperCase() === 'FIGURE';
        });
        if (!clickedListItem) {
                return;
        }
        var clickedGallery = clickedListItem.parentNode, childNodes = clickedListItem.parentNode.childNodes, numChildNodes = childNodes.length, nodeIndex = 0, index;
        for (var i = 0; i < numChildNodes; i++) {
                if (window.CP.shouldStopExecution(2)) {
                        break;
                }
                if (childNodes.nodeType !== 1) {
                        continue;
                }
                if (childNodes === clickedListItem) {
                        index = nodeIndex;
                        break;
                }
                nodeIndex++;
        }
        window.CP.exitedLoop(2);
        if (index >= 0) {
                openPhotoSwipe(index, clickedGallery);
        }
        return false;
};
var photoswipeParseHash = function() {
        var hash = window.location.hash.substring(1), params = {};
        if (hash.length < 5) {
                return params;
        }
        var vars = hash.split('&');
        for (var i = 0; i < vars.length; i++) {
                if (window.CP.shouldStopExecution(3)) {
                        break;
                }
                if (!vars) {
                        continue;
                }
                var pair = vars.split('=');
                if (pair.length < 2) {
                        continue;
                }
                params[pair[0]] = pair[1];
        }
        window.CP.exitedLoop(3);
        if (params.gid) {
                params.gid = parseInt(params.gid, 10);
        }
        if (!params.hasOwnProperty('pid')) {
                return params;
        }
        params.pid = parseInt(params.pid, 10);
        return params;
};
var openPhotoSwipe = function(index, galleryElement, disableAnimation) {
        var pswpElement = document.querySelectorAll('.pswp')[0], gallery, options, items;
        items = parseThumbnailElements(galleryElement);
        options = {
                index : index,
                galleryUID : galleryElement.getAttribute('data-pswp-uid'),
                getThumbBoundsFn : function(index) {
                        var thumbnail = items[index].el.getElementsByTagName('img')[0], pageYScroll = window.pageYOffset || document.documentElement.scrollTop, rect = thumbnail.getBoundingClientRect();
                        return {
                                x : rect.left,
                                y : rect.top + pageYScroll,
                                w : rect.width
                        };
                },
                history : false,
                focus : false
        };
        if (disableAnimation) {
                options.showAnimationDuration = 0;
        }
        gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
        gallery.init();
};
var galleryElements = document.querySelectorAll(gallerySelector);
for (var i = 0, l = galleryElements.length; i < l; i++) {
        if (window.CP.shouldStopExecution(4)) {
                break;
        }
        galleryElements.setAttribute('data-pswp-uid', i + 1);
        galleryElements.onclick = onThumbnailsClick;
}
window.CP.exitedLoop(4);
var hashData = photoswipeParseHash();
if (hashData.pid > 0 && hashData.gid > 0) {
        openPhotoSwipe(hashData.pid - 1, galleryElements[hashData.gid - 1], true);
}
};

</script>

</body>
</html>